package com.uroad.jilinpda.modle;

import java.io.Serializable;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.TimeZone;

public class OBUEF04MDL implements Serializable {

    private String obuEF04;
    private String identification;
    private int provincesNumber;
    private long entranceTime;
    private String entranceTime2;
    private String roadNetworkNumber;//网络号
    private String station16;
    private String station10;//入口收费站名 十进制
    private int axleCount;
    private String lastGantryHex;
    private long newGantryPassTime;
    private String enVehicleType;
    private long payFeeSumLocal;
    private long realFeeSumLocal;
    private long payFeeSum;
    private long realFeeSum;
    private long provTransCount;//本省累计交易成功次数
    private long totalNoCardNum;//无卡累计次数
    private String provincialAmount;//分省金额
    private int AmountIndexLN = -1;
    private String provincialEntrance;
    private long writeGantryNum;
    private int vehicleWeight;
    private String accumulatedMileage;
    private String laneStatus;

    public String getProvincialAmount(long amount) {
        return provincialAmount.substring(0,provincialAmount.length()-8)+"21"+String.format("%06X", amount);
    }

    public String getLaneStatus() {
        return laneStatus;
    }

    public void setLaneStatus(String laneStatus) {
        this.laneStatus = laneStatus;
    }

    public long getPayFeeSum() {
        return payFeeSum;
    }

    public void setPayFeeSum(long payFeeSum) {
        this.payFeeSum = payFeeSum;
    }

    public long getTotalNoCardNum() {
        return totalNoCardNum;
    }

    public void setTotalNoCardNum(long totalNoCardNum) {
        this.totalNoCardNum = totalNoCardNum;
    }

    public String getAccumulatedMileage() {
        return accumulatedMileage;
    }

    public void setAccumulatedMileage(String accumulatedMileage) {
        this.accumulatedMileage = accumulatedMileage;
    }

    public int getVehicleWeight() {
        return vehicleWeight;
    }

    public void setVehicleWeight(int vehicleWeight) {
        this.vehicleWeight = vehicleWeight;
    }

    public long getNewGantryPassTime() {
        return newGantryPassTime;
    }

    public String getNewGantryPassTimeWithFormat(String format) {
        SimpleDateFormat sdf = new SimpleDateFormat(format);
        sdf.setTimeZone(TimeZone.getTimeZone("GMT+8"));
        String dateStr = sdf.format(this.newGantryPassTime * 1000L);
        return dateStr;
    }
    public void setNewGantryPassTime(long newGantryPassTime) {
        this.newGantryPassTime = newGantryPassTime;
    }

    public String getProvincialEntrance() {
        return provincialEntrance;
    }

    public void setProvincialEntrance(String provincialEntrance) {
        this.provincialEntrance = provincialEntrance;
    }

    public long getWriteGantryNum() {
        return writeGantryNum;
    }

    public void setWriteGantryNum(long writeGantryNum) {
        this.writeGantryNum = writeGantryNum;
    }

    public long getRealFeeSum() {
        return realFeeSum;
    }

    public void setRealFeeSum(long realFeeSum) {
        this.realFeeSum = realFeeSum;
    }

    public long getProvTransCount() {
        return provTransCount;
    }

    public void setProvTransCount(long provTransCount) {
        this.provTransCount = provTransCount;
    }

    public String getRoadNetworkNumber() {
        return roadNetworkNumber;
    }

    public void setRoadNetworkNumber(String roadNetworkNumber) {
        this.roadNetworkNumber = roadNetworkNumber;
    }

    public long getPayFeeSumLocal() {
        return payFeeSumLocal;
    }

    public void setPayFeeSumLocal(long payFeeSumLocal) {
        this.payFeeSumLocal = payFeeSumLocal;
    }

    public long getRealFeeSumLocal() {
        return realFeeSumLocal;
    }

    public void setRealFeeSumLocal(long realFeeSumLocal) {
        this.realFeeSumLocal = realFeeSumLocal;
    }

    public String getEnVehicleType() {
        return enVehicleType;
    }

    public void setEnVehicleType(String enVehicleType) {
        this.enVehicleType = enVehicleType;
    }

    public String getLastGantryHex() {
        return lastGantryHex;
    }

    public void setLastGantryHex(String lastGantryHex) {
        this.lastGantryHex = lastGantryHex;
    }

    public int getAxleCount() {
        if(axleCount<2)
            return 2;
        else
            return axleCount;
    }

    public void setAxleCount(int axleCount) {
        this.axleCount = axleCount;
    }

    public String getStation10() {
        return station10;
    }

    public void setStation10(String station10) {
        this.station10 = station10;
    }

    public String getStation16() {
        return station16;
    }

    public void setStation16(String station16) {
        this.station16 = station16;
    }

    public long getEntranceTime() {
        return entranceTime;
    }

    public void setEntranceTime(long entranceTime) {
        this.entranceTime = entranceTime;
    }

    public String getEntranceTime2() {
        return entranceTime2;
    }

    public void setEntranceTime2(String entranceTime2) {
        this.entranceTime2 = entranceTime2;
    }

    public int getProvincesNumber() {
        return provincesNumber;
    }

    public void setProvincesNumber(int provincesNumber) {
        this.provincesNumber = provincesNumber;
    }

    public String getIdentification() {
        return identification;
    }

    public void setIdentification(String identification) {
        this.identification = identification;
    }

    public String getObuEF04() {
        return obuEF04;
    }

    public void setObuEF04(String obuEF04) {
        this.obuEF04 = obuEF04;
        identification = obuEF04.substring(0, 6);//AA 29 00
        entranceTime = Long.valueOf(obuEF04.substring(16, 24),16);//入口时间
        SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMddHHmmss");
        formatter.setTimeZone(TimeZone.getTimeZone("GMT+8"));
        entranceTime2 = formatter.format(new Date(entranceTime*1000));//格式化入口时间
        roadNetworkNumber = obuEF04.substring(6,10);//入口网络编号
        station16 = obuEF04.substring(10,14);//入口收费站号
        //入口收费站号十进制
        station10 = String.format("%02d", Long.parseLong(station16.substring(0, 2), 16))
                + String.format("%02d", Long.parseLong(station16.substring(2, 4), 16));
        axleCount = (int) Long.parseLong(obuEF04.substring(68, 70), 16);//轴数
        vehicleWeight = (int) Long.parseLong(obuEF04.substring(70, 76), 16);//总重
        lastGantryHex = obuEF04.substring(28, 34);//ETC门架编号
        this.newGantryPassTime = Long.parseLong(obuEF04.substring(34, 42), 16);//通行门架时间
        enVehicleType = Long.valueOf(obuEF04.substring(24, 26),16)+"";//入口车型 车型，在《收费公路联网收 费技术要求》表 4.3 基础 上，参照 JT/T489《收费公 路车辆通行费车型分类》， 定义如下： ① 客车车型： 0x01–一类客车； 0x02–二类客车； 0x03–三类客车； 0x04–四类客车； 0x05–五类客车； 0x06–六类客车； 0x07～0x0A–自定义 ②货车车型： 0x0B–一类货车； 0x0C–二类货车； 0x0D–三类货车； 0x0E–四类货车； 0x0F–五类货车； 0x10–六类货车； 0x11～0x14–自定义 ② 专项作业车车型： 0x15–一类专项作业车； 0x16–二类专项作业车； 0x17–三类专项作业车； 0x18–四类专项作业车； 0x19–五类专项作业车； 0x1A–六类专项作业车； 0x1B～0xFF–保留 注：若为牵引车，该字段写 入牵引车车型；后续《电子 收 费 单 片 式 车 载单 元 （OBU）技术要求》将与本 编码调整一致
        laneStatus = obuEF04.substring(26, 28);//出入口状态 0x00-保留，0x 01-封闭E/M 混合入口，0x02-封闭 E/M 混合出口，0x03-封闭 ETC 入口，0x04-封闭 ETC 出 口，0x05-E/M混合开放式， 0x06-ETC 开放式，0x07～ 0F 自定义，0x10-自助发 卡，0x11～FF 保留给未来 使用

        provincesNumber = Integer.parseInt(obuEF04.substring(120, 122));//累计通行省份个数

        int num = Integer.parseInt(lastGantryHex.substring(0,2),16);//十六进制转十进制
        String gantryTow = Integer.toBinaryString(num);
        String gantryTowAll = String.format("%08d", Integer.parseInt(gantryTow));
        if (!"000110".equals(gantryTowAll.substring(0,6))){//非辽宁门架省份数加一
            provincesNumber++;
        }

        payFeeSum = Long.valueOf(obuEF04.substring(122, 128),16);//累计应收金额
        realFeeSum = Long.valueOf(obuEF04.substring(128, 134),16);//累计实收金额
        provTransCount = Long.valueOf(obuEF04.substring(134, 138),16);//累计交易成功次数
        accumulatedMileage = Long.valueOf(obuEF04.substring(138, 144),16)+"";//累计计费里程
        totalNoCardNum = Long.valueOf(obuEF04.substring(144, 146),16);//标签无卡累计次数
        provincialEntrance = obuEF04.substring(146, 152);//本省入口编码
        payFeeSumLocal = Long.valueOf(obuEF04.substring(152, 158), 16);//本省累计应收金额
        writeGantryNum = Long.valueOf(obuEF04.substring(158, 160),16);//本省累计交易成功数量
        realFeeSumLocal = Long.valueOf(obuEF04.substring(160, 166),16);//本省累计实收金额

        provincialAmount = obuEF04.substring(182, 182+(8*provincesNumber));

    }
}
